package zjh_20230330;

import com.alibaba.fastjson.JSON;

import java.util.List;

public class Json {
    private String name;
    private Integer age;
    private Character gender;
//    public Json(){}
    public Json(String name,Integer age,Character gender){
        this.name = name;
        this.age = age;
        this.gender = gender;
    }
    public String toJson(){
        String s = JSON.toJSONString(this);
        return s;
    }

    public static void main(String[] args) {
        Json json = new Json("张三",12,'男');
        String s = json.toJson();
        System.out.println(s);
        Json json1 = JSON.parseObject(s, Json.class);
        System.out.println(json1);
        List<Json> jsons = JSON.parseArray(s,Json.class);
        for (Json j :
                jsons) {
            System.out.println(j);
        }
    }

    @Override
    public String toString() {
        return "Json{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Character getGender() {
        return gender;
    }

    public void setGender(Character gender) {
        this.gender = gender;
    }
}
